package set;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : SetDemo
 * @Author : 54061
 * @Date: 2022/2/8 11:34
 */
public class SetDemo {
    public static void main(String[] args) {
        //创建集合对象
        Set<String> set = new HashSet<>();
        System.out.println("set = " + set);
        //添加元素
        set.add("张三丰");
        set.add("张翠山");
        set.add("张无忌");
        System.out.println("set = " + set);

        //转数组
        Object[] objs = set.toArray();
        for (Object obj : objs){
            System.out.println("obj = " + obj);
        }
        //迭代器
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            String name = it.next();
            System.out.println("name = " + name);
        }
        //增强for
        for (String name : set){
            System.out.println("name = " + name);
        }
    }
}
